package chatRoom.server;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

public class Server {
    private ServerSocket serverSocket;
    public Server(){
        try {
            System.out.println("服务器正在启动中...........");
            serverSocket=new ServerSocket(8080);
            System.out.println("服务器启动成功.............");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    public void start(){
        try {
            while (true) {
                System.out.println("等待客户端连接............");
                Socket socket=serverSocket.accept();
                System.out.println("客户端连接成功..............");
                Thread t=new Thread(new ClientHandler(socket));
                t.start();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    public static void main(String[] args) {
        Server server=new Server();
        server.start();
    }
}
